#include<iostream>
#include<vector>
#include<deque>
using namespace std;
class Solution {
public:
    int shortestSubarray(vector<int>& nums, int k)
    {
        int left = 0, right = 0, n=nums.size(),ans=n+1;
        vector<int>s(n+1,0);
        for (int i = 1; i <= nums.size(); i++)
        {
            s[i] = s[i-1] + nums[i-1];
        }
        deque<int> de;
        de.push_back(0);
        for(int i=1;i<=n;i++)
        {
            while (!de.empty()&&s[i]-s[de.front()]>=k)
            {
                ans = min(ans,i - de.front());
                de.pop_front();
            }
            while (!de.empty() && s[i] <= s[de.back()])
                de.pop_back();
            de.push_back(i);
        }
        if (ans == n + 1)
            return -1;
        return ans;
    }
};